package cn.murky.tenant.system.biz.mq;

import cn.murky.redismq.RedisMqTemplate;
import cn.murky.tenant.system.biz.service.ISysI18nService;
import lombok.extern.slf4j.Slf4j;
import org.noear.redisx.RedisClient;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

@Component
@Slf4j
public class I18nRedisMqTemplate implements RedisMqTemplate {
    @Inject
    private RedisClient redisClient;
    @Inject
    private ISysI18nService iSysI18nService;

    @Override
    public boolean subscribe() {
        log.info("[I18nRedisMqTemplate] -> 订阅国际化语言包清空缓存主题 -> topic:{}", getTopic());
        redisClient.getBus().subscribe((topic,msg) -> {
            log.info("[I18nRedisMqTemplate] -> 消费国际化语言包清空缓存主题 -> topic:{}", topic);
            iSysI18nService.refreshLocal();
        }, getTopic());
        return true;
    }

    @Override
    public String getTopic() {
        return "topic:i18n:clean";
    }
}
